#include"common_headers.h"
int removefile31(char* file_path)
{
	//DECLARATIONS
	int collect, is_mounted, is_file_exist, is_deleted_from_nary;
	char str[300], filenameFromfilepath[50], filename[50];
	char delims[]="/";
	char *result = NULL;
	
	//INTIALIZATION:
	is_deleted_from_nary = 0;
	is_file_exist = 0;
	is_mounted = 0;
	collect = 0;
	
	//CHECK IF VFS MOUNTED
	is_mounted = validateMountState();
	if(is_mounted)
	{		
		//SEARCH IN N-ARY IF THE FILE EXIST
		is_file_exist = search_nary(file_path);
		if(is_file_exist)
		{
			//EXTRACTING THE FILENAME FROM THE FILE PATH
			strcpy(str,file_path);
			result = strtok(str, delims);
			while(result!=NULL)
			{
				strcpy(filenameFromfilepath, result);
				result=strtok(NULL, delims);
			}
			
			strcpy(filename, filenameFromfilepath);		//FILENAME EXTRACTED
			
			//-----MAY INCLUDE SOME CODE----- (FOR DELETE IN HASH TABLE)            
            
            //CHECK IF FILE EXISTS AND IS DELETED FROM N-ARY
            is_deleted_from_nary = delete_file_from_nary(file_path);            
            if(is_deleted_from_nary)
            {
            	//DELETE FROM OTHER DATA STRUCTURES, DECREMENT THE USED FD's, LOCATION BLOCK NUMBER IS MADE 0
                delete_bstnode(bst_root, file_path);
                mainHeader.usedFileDescriptors--;
                freelist[searched_Descriptor->locationblocknumber]=0;
                collect = 1;
                printf("removefile_SUCCESS\n");                
            }
        	else
		    {
		    	//FILE_TO_REMOVE_DOES_NOT_EXIST
		        printf("removefile_FAILURE: %s\n", ERR_VFS_REMOVEFILE_03);
		    }
		}
		else
		{
			//CANNOT FIND SPECIFIED FILE
			printf("removefile_FAILURE: %s\n",ERR_VFS_REMOVEFILE_01);
		}
	}
	else
	{
		//VFS NOT MOUNTED
    	printf("removefile_FAILURE: %s\n",ERR_VFS_REMOVEFILE_02);
	}

	return collect;
}

